package com.zq.learn.grpc;

import io.grpc.Channel;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

/**
 * HelloClient
 *
 * @author ZhangQi
 * @date 2020/6/1
 */
@Service
public class HelloClient {
  //客户端存根
  private GreeterGrpc.GreeterBlockingStub blockingStub;

  public GreeterGrpc.GreeterBlockingStub getBlockingStub() {
    return blockingStub;
  }

  public void setBlockingStub(Channel channel) {
    this.blockingStub = GreeterGrpc.newBlockingStub(channel);
  }

  public void greet(String name){
    //创建请求对象
    HelloRequest request = HelloRequest.newBuilder().setName(name).build();
    //获取返回对象
    HelloResponse response=blockingStub.sayHi(request);
    System.out.println("Greeting:"+response.getMessage());
  }
}
